package com.jlastu.znb.zj;


import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import com.jlastu.znb.adapter.zjAdapter;
import androidx.appcompat.app.AppCompatActivity;

import com.jlastu.znb.R;

public class zjActivity extends AppCompatActivity {
    private zjAdapter zjAdapter;
    private ListView zjListView;
    private zjManager zjManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.zj);

        zjManager = new zjManager(this);
        zjListView = findViewById(R.id.zj_list_view);
        zjAdapter = new zjAdapter(this, zjManager.getzjItems());
        zjListView.setAdapter(zjAdapter);
        zjListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                zjItem itemToRemove = zjAdapter.getItem(position);
                zjManager.removeFromzj(itemToRemove.getId());
                zjAdapter.remove(itemToRemove);
                zjAdapter.notifyDataSetChanged();
            }
        });
    }
}